import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Eric Beaudry
 * @author Jean-Sebastien Carrier
 * @author Guillaume Paquette-Boisclair
 */
public class GenPolitique1 {

	public ActionType[] computePlan(Plateau p, Double[] averageRemainingCost) {

		long startTime = System.currentTimeMillis();

		ActionType[] plan = new ActionType[p.nbCases];
		
		Integer [] reward = new Integer[p.nbCases];

		for (int i = 0; i < p.nbCases; ++i) {
			averageRemainingCost[i] = 0d;
			plan[i] = ActionType.DeuxDes;
			reward[i]= 0;
		}

		reward[p.nbCases - 1] = -20;

		while (System.currentTimeMillis() < startTime + 980) {

			for (int i = 0; i < p.nbCases; ++i) {
				FindNextBestAction(i, p, averageRemainingCost, plan, reward);
			}
		}

		
		return plan;
	}

	private void FindNextBestAction(int currentPosition, Plateau p, Double[] averageRemainingCost, ActionType[] plan, Integer[] reward) {

		double one_step = ComputeAverageRemainingCostForOneStep(currentPosition, p, averageRemainingCost);
		double one_dice = ComputeAverageRemainingCostForOneDice(currentPosition, p, averageRemainingCost);
		double two_dice = ComputeAverageRemainingCostForTwoDice(currentPosition, p, averageRemainingCost);

		if (one_step < one_dice && one_step < two_dice) {
			averageRemainingCost[currentPosition] = one_step + reward[currentPosition];
			plan[currentPosition] = ActionType.UneSeuleCase;
		} else if (one_dice < one_step && one_dice < two_dice) {
			averageRemainingCost[currentPosition] = one_dice + reward[currentPosition];
			plan[currentPosition] = ActionType.UnDe;
		} else {
			averageRemainingCost[currentPosition] = two_dice + reward[currentPosition];
			plan[currentPosition] = ActionType.DeuxDes;
		}
	}

	private double ComputeAverageRemainingCostForTwoDice(int currentPosition, Plateau p, Double[] averageRemainingCost) {

		double averageRemaining = 1d;

		for (int i = 1; i < 7; ++i) {
			for (int j = 1; j < 7; ++j) {
				averageRemaining += averageRemainingCost[p.getNextCase(currentPosition, i + j)] / 36d;
			}
		}

		return averageRemaining;
	}

	private double ComputeAverageRemainingCostForOneDice(int currentPosition, Plateau p, Double[] averageRemainingCost) {

		double averageRemaining = 1d;

		for (int i = 1; i < 7; ++i) {
			averageRemaining += averageRemainingCost[p.getNextCase(currentPosition, i)] / 6d;
		}

		return averageRemaining;
	}

	private double ComputeAverageRemainingCostForOneStep(int currentPosition, Plateau p, Double[] averageRemainingCost) {

		double averageRemaining = 1d + 1 * averageRemainingCost[p.getNextCase(currentPosition, 1)];

		return averageRemaining;
	}

	public static PolitiqueSimple generate(Plateau p, ActionType[] pol1Plan) {
		PolitiqueSimple pol = new PolitiqueSimple(p.nbCases);
		for (int i = 0; i < pol.actions.length; i++)
			pol.actions[i] = pol1Plan[i];
		return pol;
	}

	public static void main(String args[]) throws Exception {
		Plateau plateau = Plateau.load(new InputStreamReader(System.in));

		GenPolitique1 generator = new GenPolitique1();
		Double [] averageRemainingCost = new Double[plateau.nbCases];
		ActionType[] pol1Plan = generator.computePlan(plateau, averageRemainingCost);

		PolitiqueSimple pol = generate(plateau, pol1Plan);
		OutputStreamWriter out = new OutputStreamWriter(System.out);
		PolitiqueSimple.save(pol, out);
		out.close();
	}
}
